<?php
/**
*btc列表
*/
require_once 'common.inc.php';
include_once 'include/mysql_info.php';
error_reporting(0);

$tracker = new dbstuff;
$tracker->connect($dsdbhost, $dsdbuser, $dsdbpw, $dsdbname, $dspconnect);// or die (adminmsg('数据库链接错误','mysqlcontrol.inc.php?action=eidt'));
$tra_db = $tracker;
if(!$tra_db) adminmsg('数据库链接错误','mysqlcontrol.inc.php?action=eidt');
//!$tra_db ? adminmsg('数据库链接错误','mysqlcontrol.inc.php?action=eidt'):"";
//TrackerTactic数据库专用链接
$matches=parse_url($_SERVER['HTTP_REFERER']);
//$url=$matches['scheme'].'://'.$matches['host'].'/';

if('list'==$action)
{
	$action='doedit';
	$trackerlist=array();
	$query=$tra_db->query("select * from clientip ");
   	while($tracker=$tra_db->fetch_array($query))
	{
		$trackerlist[]=$tracker;
	}
	$trackerlist1=array();
	$query=$tra_db->query("select * from btc ");
   	while($tracker=$tra_db->fetch_array($query))
	{
		$trackerlist1[]=$tracker;
	}
/*	print_r($trackerlist);
	echo "<hr>";
	print_r($trackerlist1);
	
	*/
	include_once MCC_ROOT.'/templates/msystem/tralist.htm';
}
elseif('add'==$action)
{
	$action='doedit';

	include_once MCC_ROOT.'/templates/msystem/tra.htm';
}
elseif('edit'==$action)
{
	if($table=='iprange')
	{
		$sql="select * from clientip where iprange='$iprange'";
		$query=$tra_db->query($sql);
		$trackerdb=$tra_db->fetch_array($query);
		$iprange=$trackerdb['iprange'];
		$action='doedit';
		
		include_once MCC_ROOT.'/templates/msystem/tra.htm';
	}
	else if($table=='ip')
	{
		
		$sql="select * from btc where ip='$ip'";
		$query=$tra_db->query($sql);
		$trackerdb=$tra_db->fetch_array($query);
		$ip=$trackerdb['ip'];
		$action='doedit';
		
		include_once MCC_ROOT.'/templates/msystem/tra.htm';
	}
	else
	{
		adminmsg('参数传递错误','tracker_msg.inc.php?action=list');	
	}
}
elseif('doedit'==$action)
{	
$str=$opt?"opt=$opt&amp;":"";
	if($table=='iprange')
	{
		if(!preg_match('/\d{1,3}\.\d{1,3}\.\d{1,3}\.\d{1,3}\/\d{1,3}/',trim($new_iprange)))
		{	
			adminmsg('IP地址段设置错误','tracker_msg.inc.php?'.$str.'action=edit&amp;table=iprange&amp;iprange='.$iprange);	
		}
		if($iprange)
		{
			$first=0;
			$flag=0;
			$query=$tra_db->query("select * from clientip where iprange='$iprange'");
			$tempdb=$tra_db->fetch_array($query);
			if($tempdb)
			{
				$sql1="update priiprange set iprange='".$new_iprange."' where iprange='$iprange'";
				//echo $sql;
				$sql&&$tra_db->query($sql1);
				$sql="update clientip set iprange='".$new_iprange."' where iprange='$iprange'";
				//echo $sql;
				$sql&&$tra_db->query($sql);
			}
			
		}	
		else
		{
			$sql1="insert into priiprange (tacticid,priorityid,iprange) values('10','0','".$new_iprange."')";
			//echo $sql;
			$sql&&$tra_db->query($sql1);
			
			$sql="insert into clientip (tacticid,iprange) values('10','".$new_iprange."')";
			//echo $sql;
			$sql&&$tra_db->query($sql);
		}
		adminmsg('tracker设置成功','tracker_msg.inc.php?'.$str.'action=list');	
		
	}
	else if($table=='ip')
	{
		if(!preg_match('/\d{1,3}\.\d{1,3}\.\d{1,3}\.\d{1,3}:\d{1,5}/',trim($new_ip)))
			adminmsg('IP地址及端口设置错误','tracker_msg.inc.php?'.$str.'action=edit&amp;table=ip&amp;ip='.$ip);	
		if($ip)
		{
			$first=0;
			$flag=0;
			$query=$tra_db->query("select * from btc where ip='$ip'");
			$tempdb=$tra_db->fetch_array($query);
			if($tempdb)
			{
				$sql="update btc set ip='".$new_ip."' where ip='$ip'";
				//echo $sql;
				$sql&&$tra_db->query($sql);
			}
		}	
		else
		{
			$sql="insert into btc (tacticid,ip) values('10','".$new_ip."')";
			//echo $sql;
			$sql&&$tra_db->query($sql);
			
		}
		adminmsg('tracker设置成功','tracker_msg.inc.php?'.$str.'action=list');	
		
	}
}
elseif('delete'==$action)
{
	if($iprange)
	{
		$sql1="delete from priiprange where iprange='$iprange'";
		//echo $sql;
		$tra_db->query($sql1);
		$sql="delete from clientip where iprange='$iprange'";
		//echo $sql;
		$tra_db->query($sql);
		adminmsg('操作成功','tracker_msg.inc.php?'.$str.'action=list');	
	}
	else if($ip)
	{
		$sql="delete from btc where ip='$ip'";
		//echo $sql;
		$tra_db->query($sql);
		adminmsg('操作成功','tracker_msg.inc.php?'.$str.'action=list');	
	}else
	{
		adminmsg('参数传递错误','tracker_msg.inc.php?'.$str.'action=list');			
	}
}

?>